﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BookStore.Data
{
    public class paymentController
    {
        static SqlConnection con = sqlDataProvider.getConnect();
        static DataTable dt;
        #region getbyID
        public static paymentInfo getbyID(int paymentID)
        {
            paymentInfo objPayment = new paymentInfo();
            using (SqlCommand cmd = new SqlCommand("getIDPayment", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@paymentID", paymentID));
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        objPayment.paymentID = dr.GetInt32(0);
                        objPayment.paymentName = dr.GetString(1);
                        objPayment.description = dr.GetString(2);
                    }
                }
                dr.Close();
            }
            return objPayment;
        }

        #endregion

        #region getbyAll
        public static DataTable ListPayment()
        {
            using (SqlDataAdapter da = new SqlDataAdapter("listPayment", con))
            {
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                dt = new DataTable();
                da.Fill(dt);
            }
            return dt;
        }
        #endregion

        #region insert
        public static bool insertPayment(paymentInfo objPayment)
        {
            using (SqlCommand cmd = new SqlCommand("insertPayment", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@paymentName", objPayment.paymentName));
                cmd.Parameters.Add(new SqlParameter("@description", objPayment.description));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region update
        public static bool updatePayment(paymentInfo objPayment)
        {
            using (SqlCommand cmd = new SqlCommand("updatePayment", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@paymentID", objPayment.paymentID));
                cmd.Parameters.Add(new SqlParameter("@paymentName", objPayment.paymentName));
                cmd.Parameters.Add(new SqlParameter("@description", objPayment.description));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region delete
        public static bool deletePayment(int paymentID)
        {
            using (SqlCommand cmd = new SqlCommand("deletePayment", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@paymentID", paymentID));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion
    }
}
